package cn.dankal.lequ.ui.fragment.bangdan_fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.dankal.lequ.R;
import cn.dankal.lequ.commom.adapter.BaseAdapter.ViewHolder;
import cn.dankal.lequ.commom.adapter.BaseAdapter.recyclerview.CommonAdapter;
import cn.dankal.lequ.commom.adapter.RecyclerViewAdapter;
import cn.dankal.lequ.commom.util.Constant;
import cn.dankal.lequ.commom.util.MyList;

public class WangyouFragment extends Fragment {
    @Bind(R.id.tab_layout)
    TabLayout tab_layout;
    @Bind(R.id.view_pager)
    ViewPager view_pager;
    LinearLayoutManager linearLayoutManager;

    RecyclerView recyclerview, recyclerview1, recyclerview2, recyclerview3;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_bangdan_wangyou_dujia, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initTabLayout();
    }


    private void initTabLayout() {
        MyList<RecyclerView> recyclerViews = new MyList<>();
        initRecyclerView();
        initRecyclerView1();
        initRecyclerView2();
        initRecyclerView3();
        MyList<String> tablayout_titles = new MyList<>();
        recyclerViews.add(recyclerview, recyclerview1, recyclerview2, recyclerview3);
        tablayout_titles.add(Constant.JINGXUAN, Constant.QIDAI, Constant.KAICE, Constant.KAIFU);
        for (int i = 0; i < tablayout_titles.size(); i++) {
            tab_layout.addTab(tab_layout.newTab().setText((String) tablayout_titles.get(i)));
        }
        RecyclerViewAdapter adapter = new RecyclerViewAdapter(recyclerViews, tablayout_titles);
        view_pager.setAdapter(adapter);
        tab_layout.setupWithViewPager(view_pager);
        tab_layout.setTabsFromPagerAdapter(adapter);
    }

    private void initRecyclerView() {
        recyclerview = new RecyclerView(getActivity());
        linearLayoutManager = new LinearLayoutManager(getActivity());
        recyclerview.setLayoutManager(linearLayoutManager);
        recyclerview.setHasFixedSize(true);

        List<Integer> mDatas = new ArrayList<>();
        mDatas.add(1);
        mDatas.add(2);
        mDatas.add(3);
        mDatas.add(4);
        mDatas.add(5);
        mDatas.add(6);
        mDatas.add(7);
        mDatas.add(8);
        recyclerview.setAdapter(new CommonAdapter<Integer>(getActivity(), R.layout.item_currency_game, mDatas) {
            @Override
            public void convert(ViewHolder holder, Integer i) {
            }
        });
    }

    private void initRecyclerView1() {
        recyclerview1 = new RecyclerView(getActivity());
        linearLayoutManager = new LinearLayoutManager(getActivity());
        recyclerview1.setLayoutManager(linearLayoutManager);
        recyclerview1.setHasFixedSize(true);

        List<Integer> mDatas = new ArrayList<>();
        mDatas.add(1);
        mDatas.add(2);
        mDatas.add(3);
        mDatas.add(4);
        mDatas.add(5);
        mDatas.add(6);
        mDatas.add(7);
        mDatas.add(8);
        recyclerview1.setAdapter(new CommonAdapter<Integer>(getActivity(), R.layout.item_currency_game, mDatas) {
            @Override
            public void convert(ViewHolder holder, Integer i) {}
        });
    }

    private void initRecyclerView2() {
        recyclerview2 = new RecyclerView(getActivity());
        linearLayoutManager = new LinearLayoutManager(getActivity());
        recyclerview2.setLayoutManager(linearLayoutManager);
        recyclerview2.setHasFixedSize(true);

        List<Integer> mDatas = new ArrayList<>();
        mDatas.add(1);
        mDatas.add(2);
        mDatas.add(3);
        mDatas.add(4);
        recyclerview2.setAdapter(new CommonAdapter<Integer>(getActivity(), R.layout.item_currency_kaice, mDatas) {
            @Override
            public void convert(ViewHolder holder, Integer i) {
                if (i== 1)
                    holder.setVisible(R.id.v_kaice, false);

            }
        });
    }

    private void initRecyclerView3() {
        recyclerview3 = new RecyclerView(getActivity());
        linearLayoutManager = new LinearLayoutManager(getActivity());
        recyclerview3.setLayoutManager(linearLayoutManager);
        recyclerview3.setHasFixedSize(true);

        List<Integer> mDatas = new ArrayList<>();
        mDatas.add(1);
        mDatas.add(2);
        mDatas.add(3);
        mDatas.add(4);
        mDatas.add(5);
        mDatas.add(6);
        recyclerview3.setAdapter(new CommonAdapter<Integer>(getActivity(), R.layout.item_currency_kaice, mDatas) {
            @Override
            public void convert(ViewHolder holder, Integer i) {
                if (i== 1)
                    holder.setVisible(R.id.v_kaice, false);
            }
        });
    }
}
